//:C06:Generators.h
// Different ways to fill sequences.
#ifndef GENERATOR_H
#define GENERATOR_H
#include <cstring>
#include <set>
#include <cstdlib>

// A generator that can skip over numbers:
class SkipGen
{
    int i;
    int skip;
    public:
        SkipGen(int start = 0, int skip = 1)
        : i(start), skip(skip){}
        int operator()()
        {
            int r = i;
            i += skip;
            return r;
        }
};

// Generate unique random numbers from 0 to mod:
class URandGen
{
    std::set<int> used;
    int limit;
    public:
        URandGen(int lim) : limit(lim){}
        int operator()()
        {
            while(true)
            {
                int i = int(std::rand()) % limit;
                if(used.find(i) == used.end())
                {
                    used.insert(i);
                    return i;
                }
            }
        }
};

// Produces random characters:
class CharGen
{
    static const char* source;
    static const int len;
    public:
        char operator()()
        {
            return source[std::rand() % len];
        }
};
#endif